﻿using System;
using System.Data;
using System.Configuration;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections;
using Dcms.BLL;
using Dcms.Common;
using Dcms.Model;
using WebApp.AppCode;

public partial class Manage_Modle_Comment_ListComment : System.Web.UI.Page
{
    public CompetenceLib CL = new CompetenceLib();
    Dcms_CommentBLL cBll = new Dcms_CommentBLL();
    public String ROLESTR = "PRODUCT";

    protected void Page_Load(object sender, EventArgs e)
    {        
        AjaxPro.Utility.RegisterTypeForAjax(typeof(Manage_Modle_Comment_ListComment));
        CL.IsLogin();
        try
        {
            if (!IsPostBack)
            {
                int SecID = DcmsRequest.GetQueryInt("id", 0);
                string ModelFlag = DcmsRequest.GetQueryString("ModelFlag");
                int ModelKeyID = DcmsRequest.GetQueryInt("ModelKeyID", 0);
                if (ModelFlag != "" || ModelKeyID > 0)
                {
                    string strWhere = "where Comment_ModelFlag = '" + ModelFlag + "' and Comment_ModelKeyID = " + ModelKeyID;
                    if (SecID > 0)
                    {
                        strWhere += " and Comment_FlagID = " + SecID;
                    }
                    this.hidAmount.Value = cBll.GetDataCount(("select count(*) from Dcms_Comment " + strWhere).ToString());
                    this.hidSql.Value = "select * from Dcms_Comment " + strWhere + " Order by Comment_AddTime Desc";
                    ReBinder(1);
                }
                else if (Session["NewSec"] != null)
                {
                    NewSec mmnSec;
                    mmnSec = (NewSec)Session["NewSec"];
                    String WhereStr = "Where 1=1 ";
                    if (mmnSec.BeginTime != "")
                    {
                        WhereStr += " and (Comment_AddTime>='" + mmnSec.BeginTime + "')";
                    }
                    if (mmnSec.EndTime != "")
                    {
                        WhereStr += " and (Comment_AddTime<='" + mmnSec.EndTime + "')";
                    }
                    this.hidAmount.Value = cBll.GetDataCount(("select count(*) from Dcms_Comment " + WhereStr).ToString());
                    this.hidSql.Value = "select * from Dcms_Comment " + WhereStr + " Order by Comment_AddTime desc";
                    ReBinder(1);
                    Session.Remove("NewSec");
                }
            }
        }
        catch (Exception ex)
        {
            Log.LogHandler.LogError("Manage_Modle_Comment_ListComment.Page_Load", ex);
            throw ex;
        }
    }

    protected void BindRpt(object sender, PagingEventArgs e)
    {
        this.ReBinder(e.pageIndex);
    }

    private void ReBinder(int PageIndex)
    {
        this.repIntor.DataSource = cBll.GetDataListByPage(this.hidSql.Value, PageIndex, 10);
        this.repIntor.DataBind();
        pagingctrl.InitPc(Convert.ToInt32(this.hidAmount.Value), PageIndex, 10);
    }

    public String GetStrLeng(String Str)
    {
        return Utils.GetSubString(Str, 30, "...");
    }

    protected void repnew_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
        //if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        //{

        //    ((LinkButton)e.Item.FindControl("HypDelete")).Attributes.Add
        //           ("onclick", "return confirm('确定要删除该记录吗？');");
        //    if (CL.IsDelete(ROLESTR) == false)
        //    {
        //        ((LinkButton)e.Item.FindControl("HypDelete")).Visible = false;
        //    }
        //}
    }

    protected void repnew_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
    {
        //if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        //{
        //    if (e.CommandName == "delete")
        //    {
        //        int Cate_ID = DcmsRequest.GetQueryInt("CatID", 0);
        //        cBll.DeleteModelByID(Convert.ToInt32(((HiddenField)e.Item.FindControl("hidID")).Value));
        //        Response.Redirect("ListPage.aspx?CatID=" + Cate_ID + "&action=editCate",false);
        //    }
        //}
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        //int Cate_ID = DcmsRequest.GetQueryInt("CatID", 0);
        //string AllID = DcmsRequest.GetFormString("ID");
        //if (AllID.Trim().Length > 0)
        //{
        //    cBll.DeleteAllCheck(AllID);
        //    Response.Redirect("ListPage.aspx?CatID=" + Cate_ID + "&action=editCate", false);
        //}
        //else
        //{
        //    Jscript.AlertAndBack("没有选中项");
        //}
    }

    [AjaxPro.AjaxMethod]
    public string GetContentByID(int id)
    {
        string strContent = "";
        Dcms_CommentModel cModel = cBll.GetModelByID(id);
        if (cModel != null)
        {
            strContent = cModel.Comment_Content;
        }
        return strContent;
    }

    [AjaxPro.AjaxMethod]
    public string GetRevertByID(int id)
    {
        string strRevert = "";
        Dcms_CommentModel cModel = cBll.GetModelByID(id);
        if (cModel != null)
        {
            strRevert = cModel.Comment_Revert;
        }
        return strRevert;
    }

    [AjaxPro.AjaxMethod]
    public int SetRevertByID(int id, string strRevert)
    {
        int intRef = 0;
        Dcms_CommentModel cModel = cBll.GetModelByID(id);
        try
        {
            cModel.Comment_Revert = strRevert;
            cBll.Update(cModel);
            intRef = 1;
        }
        catch
        { }
        return intRef;
    }
}
